<template>
  <div class="app-container documentation-container">
    <div class="chart-container">
      <div :id="id" :class="className" :style="{height:height,width:width}" />
    </div>
  </div>
</template>
<script>
  import echarts from 'echarts'
  import resize from './mixins/resize'
  export default {
    mixins: [resize],
    props: {},
    components: {},
    data() {
      return {
        monthona:'chart',
        id:'chart',
        className:'chart',
        width:'100%',
        height:'100%',
        date:[],
        value:[],
      }
    },
    methods: {
      contentbody() {
        this.$apifn.CountenterPrises().then((ref) => {
          if (ref.data.Response.code == 200) {
            // console.log(ref.data.Response.data)
            ref.data.Response.data.month  //月统计
            ref.data.Response.data.recent //天统计
            ref.data.Response.data.recent.forEach((item)=>{
              this.date.push(item.date);
              this.value.push(item.value);

            })
            this.initChart(this.date,this.value);
            //https://gallery.echartsjs.com/editor.html?c=xrkAbwjIkf
          // console.log(this.date);
          }
        }).catch((res) => {
        })
      },
      initChart(date,val) {
        this.chart = echarts.init(document.getElementById(this.id))
        const xData = date;
        this.chart.setOption({
          backgroundColor: '#344b58',
          title: {
            text: '溯源系统平台企业',
            x: '20',
            top: '20',
            textStyle: {
              color: '#fff',
              fontSize: '22'
            },
            subtextStyle: {
              color: '#90979c',
              fontSize: '16'
            }
          },
          tooltip: {
            trigger: 'axis',
            axisPointer: {
              textStyle: {
                color: '#fff'
              }
            }
          },
          grid: {
            left: '5%',
            right: '5%',
            borderWidth: 0,
            top: 150,
            bottom: 95,
            textStyle: {
              color: '#fff'
            }
          },
          legend: {
            x: '5%',
            top: '10%',
            textStyle: {
              color: '#90979c'
            },
            data: ['企业入驻数量']
          },
          calculable: true,
          xAxis: [{
            type: 'category',
            axisLine: {
              lineStyle: {
                color: '#90979c'
              }
            },
            splitLine: {
              show: false
            },
            axisTick: {
              show: false
            },
            splitArea: {
              show: false
            },
            axisLabel: {
              interval: 0

            },
            data: xData
          }],
          yAxis: [{
            type: 'value',
            splitLine: {
              show: false
            },
            axisLine: {
              lineStyle: {
                color: '#90979c'
              }
            },
            axisTick: {
              show: false
            },
            axisLabel: {
              interval: 0
            },
            splitArea: {
              show: false
            }
          }],
          dataZoom: [{
            show: true,
            height: 30,
            xAxisIndex: [
              0
            ],
            bottom: 30,
            start: 10,
            end: 80,
            handleIcon: 'path://M306.1,413c0,2.2-1.8,4-4,4h-59.8c-2.2,0-4-1.8-4-4V200.8c0-2.2,1.8-4,4-4h59.8c2.2,0,4,1.8,4,4V413z',
            handleSize: '110%',
            handleStyle: {
              color: '#d3dee5'

            },
            textStyle: {
              color: '#fff' },
            borderColor: '#90979c'

          }, {
            type: 'inside',
            show: true,
            height: 15,
            start: 1,
            end: 35
          }],
          series: [
            {
            name: '企业入驻数量',
            type: 'bar',
            stack: 'total',
            barMaxWidth: 35,
            barGap: '10%',
            itemStyle: {
              normal: {
                color: 'rgba(255,144,128,1)',
                label: {
                  show: true,
                  textStyle: {
                    color: '#fff'
                  },
                  position: 'insideTop',
                  formatter(p) {
                    return p.value > 0 ? p.value : ''
                  }
                }
              }
            },
            data: val
          },

          ]
        })
      }
    },
    watch: {},
    computed: {
      //计算属性
    },
    created() {
      this.contentbody()
    },
    mounted() {

    }
  }
</script>
<style scoped>
  .chart-container{
    position: relative;
    width: 100%;
    height: calc(100vh - 82px);
  }
  .app-container {

  .roles-table {
    margin-top: 30px;
  }

  .permission-tree {
    margin-bottom: 30px;
  }

  }
  /*手机*/
  @media screen and (min-width: 100px) and (max-width: 960px) {
    .top {
      width: 100%;
      height: 147px;

    }

    .add_zhandian {
      width: 100%;
      height: 38px;
    }

    .selech {
      width: 100%;
      height: 50px;
    }
  }

  /*PC*/
  @media screen and (min-width: 960px) and (max-width: 1900px) {
    .top {
      width: 100%;
      height: 50px;
    }

    .add_zhandian {
      width: 20%;
      height: 100%;
      float: left;
    }

    .selech {
      width: 79%;
      height: 100%;
      float: right;

    }
  }
</style>
